<template>
	<view class="container">
		<navbar title="推广申请"></navbar>
		<view class="wrap" :style="{height:'calc(100% - '+ headAllHeight +'px)'}">
			<image src='../static/apply-bg.png' mode="aspectFill"></image>
			<view class="apply-wrap">
				<view class="title">
					<image src='../static/info-bg.png'></image>
					<view class="title-con">
						信息登记
					</view>
				</view>
				<view class="apply-list">
					<view class="apply-item">
						<label>用户姓名</label>
						<view class="input">
							<input type='text' placeholder="请输入你的真实姓名" v-model="form.share_real_name"/>
						</view>
					</view>
					<view class="apply-item">
						<label>联系电话</label>
						<view class="input">
							<input type='number' placeholder="请输入您的联系方式" v-model="form.share_contact_mobile"/>
						</view>
					</view>
				</view>
				<button class="btn line-center" :disabled="isDisabled" :loading="isDisabled" @tap='applyShare'>立即申请</button>
				<view class="xieyi line-center" @tap='agree'>
					<uni-icons type="checkbox-filled" size="20" :color="isChecked ? '#107BF6':'#EDEDF0'"></uni-icons>
					<view class="text">我已阅读<text @tap.stop='toAgree()'>《代理商协议》</text></view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	const app = getApp();
	export default {
		data() {
			return {
				headAllHeight:app.globalData.headAllHeight,
				isDisabled:false,
				form:{
					share_contact_mobile:'',
					share_real_name:''
				},
				isChecked:false,
			};
		},
		methods:{
			agree(){
				this.isChecked = !this.isChecked
			},
			toAgree(){
				uni.navigateTo({
					url:'/pages/user-page/agreement/agreement?type=1'
				})
			},
			applyShare(){
				const that = this;
				let form = that.form;
				if(!form.share_real_name){
					uni.showToast({
						title:'请输入真实姓名',
						icon:'none',
						mask: true
					})
					return;
				}
				if(!form.share_contact_mobile){
					uni.showToast({
						title: '请输入手机号',
						icon: 'none',
						mask: true
					})
					return;
				}
				if (!(/^1[3456789]\d{9}$/.test(form.share_contact_mobile))) {
					uni.showToast({
						title: "手机号码不合法，请重新输入",
						icon: 'none',
						mask: true
					});
					return;
				}
				if(!that.isChecked){
					uni.showToast({
						title: "请阅读并同意《代理商协议》",
						icon: 'none',
						mask: true
					});
					return;
				}
				that.isChecked = true;
				app.globalRequest({
					api: app.getApi().promotion.applyShare,
					method:'POST',
					data:form
				}).then(res => {
					if (res.code == 0) {
						uni.showToast({
							title: res.msg,
							icon: 'none',
							mask: true
						});
						
						setTimeout(()=>{
							uni.navigateBack({
								delta:1
							})
							that.isDisabled = false
						},200)
					} else{
						uni.showToast({
							title: res.msg,
							icon: 'none',
							mask: true
						});
						that.isDisabled = false
					}
				}).catch(err => {
					that.isDisabled = false
				})
			}
		}
	}
</script>
<style>
	page{
		width: 100%;
		height: 100%;
	}
</style>
<style lang="scss" scoped>
	.container{
		height: 100%;
		width: 100%;
		overflow-y: hidden;
	}
	.wrap{
		width: 100%;
		image{
			width: 100%;
			height: 100%;
		}
		position: relative;
	}
	.apply-wrap{
		width: 702rpx;
		height: 582rpx;
		padding:0 24rpx;
		box-sizing: border-box;
		background: #FFFFFF;
		border-radius: 24rpx;
		position: absolute;
		bottom:130rpx;
		left:0;
		right:0;
		margin:auto;
		.title{
			width: 396rpx;
			height: 84rpx;
			margin:-10rpx auto;
			position: relative;
			.title-con{
				width: 100%;
				height: 100%;
				position: absolute;
				left:0;
				top:0;
				text-align: center;
				line-height: 90rpx;
				font-size: 32rpx;
				font-weight: bold;
				color:#fff;
			}
		}
	}
	.apply-list{
		margin-top:40rpx;
		.apply-item{
			width: 100%;
			height: 104rpx;
			background: #F6F7FF;
			border-radius: 16rpx;
			display: flex;
			align-items: center;
			padding:0 22rpx;
			box-sizing: border-box;
			margin-bottom: 22rpx;
			label{
				color:#1D1D1D;
				font-weight: bold;
			}
			.input{
				flex:1;
				height: 100%;
				padding:0 0rpx 0 38rpx;
				box-sizing: border-box;
				input{
					width: 100%;
					height: 100%;
					font-size: 28rpx;
				}
			}
		}
	}
	.btn{
		width: 640rpx;
		height: 94rpx;
		background: #107BF6;
		border-radius: 48rpx;
		color:#fff;
		font-size: 32rpx;
		margin-top:50rpx;
	}
	.xieyi{
		padding-top:22rpx;
		.text{
			color:#EDEDF0;
			text{
				color:#107BF6;
			}
		}
	}
</style>
